package com.bootdo.app.utils;

import com.bootdo.app.htmlVO.car.Car;
import com.bootdo.app.htmlVO.car.CarGoods;
import com.bootdo.app.htmlVO.car.CarInfo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


/**
 * 购物车工具类
 */
public class CarUtils {


    /**
     * 根据状态摘除相应购物车信息
     * @param car
     * @param ischick
     * @return
     */
    public static Car isChick(Car car,Integer ischick){
        List<CarInfo> carInfoList = car.getCarInfo();
        for(CarInfo carInfo : carInfoList){
            List<CarGoods> goodList = carInfo.getGoodList();
            Iterator<CarGoods> iterator = goodList.iterator();
            while (iterator.hasNext()){
                if (iterator.next().getIsChick() == ischick){
                    iterator.remove();
                }
            }
        }
        Iterator<CarInfo> carit = carInfoList.iterator();
        System.out.println(carInfoList);
        while (carit.hasNext()){
            if (carit.next().getGoodList().size() == 0){
                carit.remove();
            }
        }
        return car;
    }







}
